package demo04

/**
 * @author xiaoZhao
 * @date 2022/6/28
 * @describe 函数参数
 */
object Test02_FunctionParameter {
  def main(args: Array[String]): Unit = {
    // 可变参数
    // WrappedArray 底层会转变成一个集合类型，类似于Java中的数组
    def f1(str: String*): Unit = {
      println(str)
    }

    f1("alice")
    f1("alice", "aaa", "bbbb")


    def f2(str1: String, str2: String*): Unit = {
      println(str1 + " , " + str2)
    }

    f2("alice")
    f2("alice", "aaa", "bbbb")


    //参数默认值
    def f3(name: String = "lisi"): Unit = {
      println(name)
    }

    f3()
    f3("wangwu")

    // 带名参数
    def f4(name: String = "lala", age: Int): Unit = {
      println(s"${age}岁的${name}在吃饭")
    }

    f4("bob", 12)
    f4(age = 13, name = "haha")
    f4(age = 15)
  }
}
